#include <head.h>

void *func_1(void*I)
{
    int fd = open("main.txt", O_RDWR | O_CREAT, 0666);
    int fd_copy = open("copy.txt", O_RDWR | O_CREAT, 0666);

    char buf_1[1024];
    lseek(fd,0,SEEK_SET);
    lseek(fd_copy,0,SEEK_SET);
    int byte_1 = read(fd,buf_1,249);
    buf_1[byte_1] ='\0';

    write(fd_copy,buf_1,byte_1);

    close(fd);
    close(fd_copy);
}

void *func_2(void*I)
{
    int fd = open("main.txt", O_RDWR | O_CREAT, 0666);
    int fd_copy = open("copy.txt", O_RDWR | O_CREAT, 0666);


    char buf_2[1024];
    lseek(fd,249,SEEK_SET);
    lseek(fd_copy,249,SEEK_SET);
    int byte_2 = read(fd,buf_2,sizeof(buf_2));
    buf_2[byte_2] = '\0';

    write(fd_copy,buf_2,byte_2);
    
    close(fd);
    close(fd_copy);
}

int main(int argc, char const *argv[])
{


    pthread_t Tid_1 = 0;
    pthread_t Tid_2 = 0;

    pthread_create( &Tid_1,NULL,func_1,NULL);
    pthread_create( &Tid_2,NULL,func_2,NULL);

    pthread_join(Tid_1,NULL);
    pthread_join(Tid_2,NULL);


    return 0;
}
